<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var x = 100;
      y = "abc"; // 等价于window.y='abc' 全局变量
      console.log(x, y);
      console.log(this.y); //这里的this代表的是window

      var name = "李四"; // window.name='李四'
      var age = 12;
      var obj = {
        //对象
        name: "张三",
        age: 16,
        fn: function () {
          console.log(this.name + this.age); //this指向的是当前执行这个函数的对象
        },
      };
      obj.fn();
      console.log(this.name + this.age); //this指向的是window
    </script>
  </body>
</html>
